<template>
	<view class="flex-col homepage">
		<view class="flex-col wrapper">
			<view class="flex-row wraper-row">
				<u-avatar class="avatar" :size="90" :src="doctor.img"></u-avatar>
				<view class="u-line-1 text">{{doctor.doctorName}}</view>
				<view class="u-line-1 text-two">主任医生</view>
			</view>
			<u-line class="line" margin="0rpx 0rpx 30rpx 4rpx"></u-line>
			<view class="flex-row wraper-row-two">
				<view class="u-line-1 text-three">就诊医院</view>
				<view class="u-line-1 text-four">{{Hospital.campusName}}</view>
			</view>
			<u-line class="line" margin="0rpx 0rpx 30rpx 4rpx"></u-line>
			<view class="flex-row wraper-row-three">
				<view class="u-line-1 text-five">医院地址</view>
				<view class="u-line-1 text-six">{{Hospital.campusAddress}}</view>
			</view>
			<u-line class="line-two" margin="0rpx 0rpx 30rpx 0rpx"></u-line>
			<view class="flex-row wraper-row-four">
				<view class="u-line-1 text-seven">就诊科室</view>
				<view class="u-line-1 text-eight">{{Department1.divisionName}}-{{Department2.divisionName}}</view>
			</view>

			<u-line class="line-two" margin="0rpx 0rpx 30rpx 0rpx"></u-line>
			<view class="flex-row wraper-row-six">
				<view class="u-line-1 text-eleven">候诊时间</view>
				<view class="u-line-1 text-twelve">{{time}}</view>
			</view>
			<u-line class="line-three" margin="0rpx 0rpx 30rpx 0rpx"></u-line>
			<view class="flex-row wraper-row-seven">
				<view class="u-line-1 text-thirteen">费用</view>
				<view class="flex-row box">
					<u-icon class="icon-rmb" name="rmb" color="#df2020"></u-icon>
					<view class="flex-row box-col">
						<view class="u-line-1 text-fourteen">{{doctor.registration}}</view>
						<view class="u-line-1 text-fifteen">(就诊时支付)</view>
					</view>
				</view>
			</view>
			<u-line class="line-four" margin="0rpx 0rpx 30rpx 0rpx"></u-line>
			<view class="flex-row wraper-row-eight">
				<view class="u-line-1 text-sixteen">预约时间</view>
				<view class="u-line-1 text-seventeen">{{dataShow.time}} {{dataShow.day}}</view>
			</view>
		</view>
		<view class="flex-col wrapper-two">
			<view class="flex-row wraper-row-nine">
				<view class="u-line-1 text-eighteen">就 诊 人</view>
				<view class="u-line-1 text-nineteen">{{patient.name}}</view>
			</view>
			<u-line class="line-five" margin="0rpx 0rpx 30rpx 0rpx"></u-line>
			<view class="flex-row wraper-row-ten">
				<view class="u-line-1 text-twenty">身份证号</view>
				<view class="u-line-1 text-20">{{patient.number}}</view>
			</view>
		</view>
		<view class="flex-row wrapper-three">
			<view class="u-line-1 text-21">挂号前仔细阅读</view>
			<view class="u-line-1 text-22">《挂号须知》</view>
		</view>
		<u-button class="button" @click="confirm" type="success">
			确认预约
		</u-button>

		<view>
			<u-popup :show="show" :round="10" @close="close" :overlay='overlay' @open="open" mode="center"
				:closeable="closeable" :closeOnClickOverlay="closeOnClickOverlay">
				<view style="width: 300px;height: 200px;">
					<p style="font-size: 18px;text-align: center;margin-top: 25px;">请输入就诊卡密码</p>
					<u-code-input v-model="value" :maxlength="6" style="margin-left: 15px;margin-top: 30px;" dot></u-code-input>
					<u-button @click="zhifu" type="primary" text="确定" style="width: 250px;margin-top: 30px;"></u-button>
				</view>
			</u-popup>

		</view>
	</view>
</template>
<script>
	import request from '@/utils/requestConfig.js'
	export default {
		
		data() {
			return {
				URL: 'http://localhost:9000/', //主域名
				show: false,
				overlay: true,
				closeable: true,
				closeOnClickOverlay: true,
				
				//就诊卡密码
				value:'',
				time: '',
				//院区id
				HospitalId: '',
				//院区
				Hospital: {},
				//一级科室id
				DepartmentId1: '',
				Department1: {},
				//二级科室id
				DepartmentId2: '',
				Department2: {},

				//就诊人
				patient: [],
				//医生
				doctor: [],
				//预约时间
				dataShow: '',

				//候诊id
				hozhenId: '',

				//预约id
				yuyueId: '',

			}
		},
		onLoad() {
			this.getId()

		},
		methods: {
		
			getId() {
				this.time = uni.getStorageSync('time')
				this.HospitalId = uni.getStorageSync('HospitalId')
				this.DepartmentId1 = uni.getStorageSync('DepartmentId1')
				this.DepartmentId2 = uni.getStorageSync('DepartmentId2')
				this.patient = uni.getStorageSync('patient')
				this.doctor = uni.getStorageSync('doctor')
				this.dataShow = uni.getStorageSync('dataShow')

				this.getHospital() //获取院区
				this.getDepartment() //获取科室
			},
			zhifu(){
				request.post("/user/user/patient-card/deductMoney",
				{
					money:this.doctor.registration,
					hospitalNumber:this.patient.patientCard.cardNo,
				}).then((res) => {
						console.log("成功")
						
						//加入到redis队列 进行排队
						this.setRedis();
						
						
						//添加候诊
						this.addhozhen()
						
						
						
						uni.showToast({
							title: '预约成功',
							duration: 2000,
						})
						
						
						setTimeout(() => {
							
							uni.reLaunch({
								url: '../index/index'
							})
						}, 2000)
						
						
				
				
					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
			confirm() {
				console.log("确认预约")
				
				
				
				this.show = true
				

			},
			addyuyue() {
				this.$axios.get("/appointment/appointment/appointment/addhesuan/" + this.patient.id + '/' + this
						.DepartmentId1 +
						'/' + this.doctor.id + '/' + this.Hospital.id + '/' + this.hozhenId)
					.then((
						res) => {
						console.log("生成预约记录成功")
						this.yuyueId = res.data.data.id
						console.log(res.data.data.id)
						console.log("返回的主键预约ID" + this.yuyueId)

						
					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
				
			addhozhen() {
				this.$axios.get("/record/record/waiting-record/addhozhen/" + this.patient.id + '/' + this.DepartmentId1 +
						'/' + this.doctor.id + '/' + this.time)
					.then((
						res) => {

						console.log("生成候诊记录成功")
						this.hozhenId = res.data.data.id
						console.log(res.data.data.id)
						console.log("返回的主键ID" + this.hozhenId)
						//添加预约挂号记录表
						this.addyuyue();

						//生成记录表记录
						this.addjilu();
						

					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
			addjilu(){
				
				uni.request({
					url: this.URL + 'record/record/record/addjilu',
					method: "POST",
					data: {
						//就诊人id
						patientId:this.patient.id,
						//就诊卡id
						patientcardDi: this.patient.patientCard.id,
						divisionTypeId:this.DepartmentId1,
						money: this.doctor.registration,
						appointmentId:this.yuyueId,
						doctorId:this.doctor.id,
						campusId:this.HospitalId,
						
					},
					success: (res) => {
						if (res.data.code == 20000) {
							console.log("生成记录表记录成功")
							
							
						}
					}
				})
			},
			
			setRedis(){
				this.$axios.get("/user/user/user/setRedis/" + this.patient.id)
					.then((
						res) => {
						console.log("加入redis队列成功")
				
				
					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
			getDepartment() {
				this.$axios.get("/other/other/division-type/getDepartment/" + this.DepartmentId1 + '/' + this
						.DepartmentId2).then((
						res) => {

						console.log("成功")
						this.Department1 = res.data.data.divisionType1
						this.Department2 = res.data.data.divisionType2
						//console.log(this.Hospital)
						//this.Doctors = res.data.data.list

					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
			getHospital() {
				var id = this.HospitalId
				this.$axios.get("/user/user/campus/findByCampusID/" + id).then((
						res) => {

						console.log("成功")
						this.Hospital = res.data.data.campus
						console.log(this.Hospital)
						//this.Doctors = res.data.data.list

					}) //请求成功
					.catch((error) => {
						console.log(error);
					});
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>
<style lang="scss" scoped>
	/** 全局样式-开始,建议放在公共css样式文件中,比如common.css 或app.vue文件 */

	html,
	body {
		margin: 0;
		width: 100%;
		height: 100%;
		font-size: 16px
	}

	view,
	text,
	image {
		position: relative;
		box-sizing: border-box;
		flex-shrink: 0;
	}

	.flex-col {
		display: flex;
		align-items: flex-start;
		flex-direction: column;
	}

	.flex-row {
		display: flex;
		align-items: flex-start;
	}

	.flex-col .flex-row {
		width: 100%
	}

	/** 全局样式-结束*/

	.homepage {
		padding: 40rpx 23rpx 0rpx 23rpx;

		.wrapper {
			width: 100%;
			margin-bottom: 40rpx;
			padding: 30rpx 0rpx 42rpx 20rpx;
			background: #ffffff;
			font-weight: 400;

			.wraper-row {
				width: 360rpx;
				margin: 0rpx 0rpx 22rpx 10rpx;

				.avatar {
					margin-right: 36rpx;
				}

				.text {
					width: 96rpx;
					margin: 22rpx 16rpx 0rpx 0rpx;
					font-size: 32rpx;
				}

				.text-two {
					width: 122rpx;
					margin-top: 26rpx;
					font-size: 24rpx;
				}
			}

			.line {
				width: 654rpx;
			}

			.wraper-row-two {
				width: 582rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-three {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-four {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.wraper-row-three {
				width: 582rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-five {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-six {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.line-two {
				width: 664rpx;
			}

			.wraper-row-four {
				width: 582rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-seven {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-eight {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.wraper-row-five {
				width: 582rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-nine {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-ten {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.wraper-row-six {
				width: 582rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-eleven {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-twelve {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.line-three {
				width: 664rpx;
			}

			.wraper-row-seven {
				width: 496rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-thirteen {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.box {
					width: 348rpx;
					justify-content: space-between;
					padding: 4rpx 102rpx 6rpx 2rpx;
					color: #ffffff;

					.icon-rmb {
						width: 28rpx;
						margin-top: 4rpx;
					}

					.box-col {
						width: 216rpx;

						.text-fourteen {
							width: 56rpx;
							margin-right: -4rpx;
							color: #d41616;
						}

						.text-fifteen {
							width: 164rpx;
							color: #b2bdd6;
						}
					}
				}
			}

			.line-four {
				width: 664rpx;
			}

			.wraper-row-eight {
				width: 582rpx;
				justify-content: space-between;
				margin-left: 10rpx;

				.text-sixteen {
					width: 148rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-seventeen {
					width: 434rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}
		}

		.wrapper-two {
			width: 698rpx;
			margin-right: auto;
			margin-bottom: 30rpx;
			margin-left: auto;
			padding: 30rpx 19rpx 36rpx 19rpx;
			background: #ffffff;

			.wraper-row-nine {
				width: 248rpx;
				justify-content: space-between;
				margin: 0rpx 0rpx 30rpx 10rpx;

				.text-eighteen {
					width: 132rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-nineteen {
					width: 102rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}

			.line-five {
				width: 100%;
			}

			.wraper-row-ten {
				width: 450rpx;
				justify-content: space-between;
				margin-left: 10rpx;

				.text-twenty {
					width: 132rpx;
					font-size: 32rpx;
					color: #c0c0c0;
				}

				.text-20 {
					width: 304rpx;
					font-size: 32rpx;
					font-weight: 300;
				}
			}
		}

		.wrapper-three {
			width: 348rpx;
			margin-left: 2rpx;

			.text-21 {
				width: 190rpx;
				margin-right: -10rpx;
				font-size: 24rpx;
				color: #dddddd;
			}

			.text-22 {
				width: 170rpx;
				font-size: 24rpx;
				color: #2979ff;
			}
		}

		.button {
			width: 698rpx;
			display: block;
			margin-right: auto;
			margin-left: auto;
			font-size: 32rpx;
			background: #006eff;
			color: #f2f8ff;
		}
	}
</style>
